package com.gxz.springboot.controller;

import com.gxz.springboot.bean.Monster;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import java.util.List;
import java.util.Map;

@RestController
public class ParameterController {

    @GetMapping("/monster/{id}/{name}")
    public String pathVariable(@PathVariable("id") Integer idx,@PathVariable("name") String namex,@PathVariable Map<String,String> map ){
        System.out.println("id=="+idx);
        System.out.println("name=="+namex);        System.out.println("map=="+map);
         return "success";
    }

    /**
     *
     * @RequestHeader("Host")  获取http请求头的host信息
     * @RequestHeader Map<String,String> header  header: 获取http请求的所有信息
     *
     *
     */
    @GetMapping("/requestHeader")
    public String requestHeader(@RequestHeader("Host") String host,@RequestHeader Map<String,String> header,@RequestHeader("accept") String accept) {
        System.out.println("host"+host);
        System.out.println("header-"+header);
        System.out.println("acccept-"+accept);

        return "success";
    }

    /**
     *  如果我们希望所有的请求参数的值都获取到,可以通过
     * @param username
     * @param fruits
     * @return
     */
    @GetMapping("/hi")
    public String hi(@RequestParam(value = "name",required = true) String username,
                     @RequestParam("fruit")List<String> fruits,
                     @RequestParam Map<String,String> paras){
        System.out.println("username=="+username);
        System.out.println("fruit-"+fruits);
        System.out.println("paras-"+paras);
       return "success";
    }

    @GetMapping("/cookie")
    public String cookie(@CookieValue(value = "cookie_key",required = false) String cookie_value
     ,@CookieValue(value = "username",required = false) Cookie cookie ) {
        System.out.println("cookie_value_" + cookie_value);
        if (cookie != null) {
            System.out.println("username-" + cookie.getName() + "-" + cookie.getValue());

        }
        return "success";
    }

    /**
     *  @PostMapping 是整体取出Post请求内容
     *
     */
    @PostMapping("/save")
    public String postMethod(@RequestBody  String content){
        System.out.println("content-"+content);
        return "success";
    }

    @PostMapping("/savemonster")
    public String saveMonster(Monster monster){
        System.out.println("monster= " + monster);
        return "success";
    }





}
